﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Nvigorate.Repository.Test
{
    public class RegisterVehicleCommand : BaseCommand<IRegisterVehicle, RegisterVehicle>
    {
        public override ICommandResult Execute(RegisterVehicle dto)
        {
            var vehicleRepository = GetRepository<Vehicle>();
            var driver = Repository.Get<Person, int>(p => p.Id, dto.PersonId);
            var vehicle = vehicleRepository.Get<Vehicle, int>(v => v.Id, dto.VehicleId);

            using(var scope = NotificationScope.Create())
            {
                driver.AddVehicle(vehicle);
                return scope.GetResult();
            }
        }

        public RegisterVehicleCommand(IRepository<IRegisterVehicle> repository) : base(repository)
        {
        }
    }


}
